package com.itlong.cloud.rabbitmq.consumer;

import com.itlong.cloud.property.service.IPropertyPersonService;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * <desc>
 *      用户服务-XXX业务操作队列消费者。
 * </desc>
 *
 * @createDate 2017/9/6
 */
@Component
public class UserConsumer {

    private static final Logger LOG = LoggerFactory.getLogger(UserConsumer.class);

    @Autowired
    IPropertyPersonService iPropertyPersonService;

    @RabbitListener(queues = "queueDed")
    public void process(Message message, Channel channel) throws InterruptedException, IOException {
        try{
            byte[] body = message.getBody();
            System.out.println("用户服务消费 : " + new String(body));
            System.out.println(message.getMessageProperties().getMessageId());
          /*  PersonPO personPO = new PersonPO(new String(body));
            iPropertyPersonService.savePerson(personPO);*/
            //String [] s = new String[2];
            //System.out.println(s[3]);
            //Thread.sleep(70000);
        }catch (Exception ex){
            channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
            LOG.error("【RabbitMQ_XXX业务消费端】:消费异常",ex);
        }finally {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }
    }

}
